package com.dq.controller.op.opmerchant.message;

import com.dq.annotation.aop.SysLog;
import com.dq.exception.customException.AdminException;
import com.dq.vo.Vo;
import com.dq.domain.message.oneself.ApprovalMessage;
import com.dq.service.AllService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * @author cf
 */
@Api(description = "消息通用方法")
@RestController
@RequestMapping("sys/org/message/")
public class BackMessageController extends AllService {

    @ApiOperation("消息查看")
    @GetMapping("/look/{id}/{type}")
    public Vo updateType(@PathVariable @ApiParam(value = "消息ID") Long id, @PathVariable @ApiParam(value = "返给页面【messageTypeEn】字段值") String type) throws AdminException {

        messageService.look(id, type);

        return new Vo(HttpStatus.OK);
    }


    @ApiOperation("删除采购消息")
    @SysLog("删除采购消息")
    @PostMapping("/delete/{id}")
    @RequiresPermissions("sys:approvalMessage:delete")
    public Vo delete(@PathVariable @ApiParam(value = "id") Long id) throws AdminException {
        ApprovalMessage orgPositionQuery = dao.get(ApprovalMessage.class, id);
        if (orgPositionQuery == null) {
            throw new AdminException("无对应id对象");
        }

        orgPositionQuery.setDeleted(true);
        approvalMessageService.update(orgPositionQuery);
        return new Vo(HttpStatus.OK);
    }

}
